<html>
<head><meta charset="utf-8"><title>HashMap::insert vs HashSet::insert · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/HashMap.3A.3Ainsert.20vs.20HashSet.3A.3Ainsert.html">HashMap::insert vs HashSet::insert</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="167959187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/HashMap%3A%3Ainsert%20vs%20HashSet%3A%3Ainsert/near/167959187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/HashMap.3A.3Ainsert.20vs.20HashSet.3A.3Ainsert.html#167959187">(Jun 12 2019 at 15:38)</a>:</h4>
<p>I am reminded of this annoying footgun:</p>
<blockquote>
<p>If the map did not have this key present, None is returned.</p>
<p>If the set did not have this value present, true is returned.</p>
</blockquote>



<a name="167959227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/HashMap%3A%3Ainsert%20vs%20HashSet%3A%3Ainsert/near/167959227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/HashMap.3A.3Ainsert.20vs.20HashSet.3A.3Ainsert.html#167959227">(Jun 12 2019 at 15:39)</a>:</h4>
<p>that one has bitten me so many times</p>



<a name="167961495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/HashMap%3A%3Ainsert%20vs%20HashSet%3A%3Ainsert/near/167961495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/HashMap.3A.3Ainsert.20vs.20HashSet.3A.3Ainsert.html#167961495">(Jun 12 2019 at 16:00)</a>:</h4>
<p>fwiw I personally consider the bool return type on HashSet::insert to be a mistake, we should've made it an enum (with methods to check for each variant, perhaps)</p>



<a name="167961537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/HashMap%3A%3Ainsert%20vs%20HashSet%3A%3Ainsert/near/167961537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/HashMap.3A.3Ainsert.20vs.20HashSet.3A.3Ainsert.html#167961537">(Jun 12 2019 at 16:00)</a>:</h4>
<p>I don't think I've ever gotten the true/false to match with what I actually wanted in code</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>